﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>版辊信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/layui/layui.js"></script>
    <link href="~/Content/Scripts/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <div class="layui-fluid" style="margin:5px">
        <div style="float:left">
            <div id="treeNav" class="demo-tree demo-tree-box" style="width: 200px; height: 500px; overflow: scroll;float:left;background-color:white"></div>

        </div>
        <div style="float:left;width:78%;">
            <div class="layui-card">
    
         
                <div class="layui-card-body layui-table-body layui-table-main">

                    <form id="AddForm" class="layui-form layui-col-space5">
                        <div class="layui-form-item">
                            <label class="layui-form-label">类型编码</label>
                            <div class="layui-input-inline">
                                <input type="text" name="trCode" class="layui-input" id="trCode" readonly/>
           
                            </div>

                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">类型名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="trName" class="layui-input" id="trName" />

                            </div>
                     
                        </div>
                    
                      
                    </form>
                    <span style="margin-top:15px;margin-left:55px;margin-bottom:30px">
                        <xblock>
                            <button class="layui-btn" onclick="saveData(1)"><i class="layui-icon"></i>添加</button>
                            <button class="layui-btn" onclick="saveData(0)"><i class="layui-icon">&#xe642;</i>修改</button>
                            <button class="layui-btn" onclick="DelTypeData()"><i class="layui-icon">&#xe640;</i>删除</button>
                        </xblock>
                    </span>
                    <br />
                </div>
            </div>


        </div>
    </div>
</body>

</html>

<script>

    var type = "";
    var dType="";
    $(function () {
        dType = getUrlVariable("dType");
        loadData();
    })
    /**
    加载树数据
    **/
    function loadData() {
        $.ajax({
            url: "../Basis/CommonTree",
            dataType: "json",
            type: "POST",
            data: { tCode: dType },
            success: function (data) {
                if (data.Result) {
                    loadTree(data.Data);
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    var trCode = "";
    /**
    类型树加载方法
    **/
    function loadTree(data) {
        var tree = layui.tree;
        var layer = layui.layer;
        var util = layui.util;
        //开启节点操作图标
        tree.render({
            elem: '#treeNav'
          , data: data
          , click: function (obj) {
              trCode = obj.data["id"];
              $("input[ name='trCode']").val(obj.data["id"]);
              $("input[ name='trName']").val(obj.data["title"]);
          }
        });
    }

    /**
    保存数据信息
    **/
    function saveData(operType) {
        if (trCode == "") {
            layer.msg("请先选择数据"); return;
        }
        $.ajax({
            url: "../Basis/SaveTypeData",
            data: { data: JSON.stringify(FormToJson("AddForm")), operType: operType, dType: dType },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    layer.msg("信息保存成功");
                    loadData();
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }

    function DelTypeData() {
        if (trCode == "") {
            layer.msg("请先选择数据"); return;
        }
        $.ajax({
            url: "../Basis/DelTypeData",
            data: { trCode:trCode },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    layer.msg("信息删除成功");
                    loadData();
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
</script>
